﻿<%@page import="com.mixky.app.ApplicationParameters"%>
<%@page contentType="text/plain;charset=UTF-8"%>
<jsp:directive.page import="java.text.SimpleDateFormat" />
<jsp:directive.page import="java.util.Date" />
<jsp:directive.page import="java.io.FileOutputStream" />
<jsp:directive.page import="java.io.File" />
<jsp:directive.page import="java.io.BufferedInputStream" />
<jsp:directive.page import="java.io.ByteArrayOutputStream"/>
<jsp:directive.page import="org.p3p.image.encrypt.JpegEncrypt"/>

<%

	System.out.println("test="+request.getParameter("userid"));
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
	String rootPath = ApplicationParameters.instance().getFileUploadPath();
	//System.out.println(rootPath);
	String cdStr=sdf.format(new Date());
	//String filename = "photo_" + cdStr	+ ((int) (Math.random() * 100000 + 10000)) + ".jpg";
	String filename = "/user.jpg";
	System.out.println(rootPath);
	int v = 0;
	BufferedInputStream inputStream = new BufferedInputStream(request
	.getInputStream());
	byte[] bytes = new byte[1024];
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	while ((v = inputStream.read(bytes)) > 0) {
		baos.write(bytes, 0, v);
	}
	inputStream.close();
	baos.close();	
	//加入认证
	byte[] tmp = baos.toByteArray();
	JpegEncrypt en=new JpegEncrypt();
	byte[] tmp1=en.encrypt(cdStr+"-用户姓名或者标识",tmp);
	tmp=null;
	File f1=new File(rootPath
			+  filename);
	FileOutputStream fos = new FileOutputStream(f1);
	fos.write(tmp1);
	fos.close();
 	String keyword=en.decrypt(f1);
	//读取加密信息
	System.out.println(filename);
	out.write(filename);
%>
